

package com.kimo.shop.user.admin.controller;

import com.kimo.shop.user.comment.model.UserLevelCategory;
import com.kimo.shop.user.comment.service.UserLevelCategoryService;
import com.kimo.shop.common.annotation.SysLog;

import javax.validation.Valid;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.kimo.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;


/**
 *
 *
 * @author kimo-taozhouchuan
 * @date 2020-02-26 16:03:14
 */
@RestController
@AllArgsConstructor
@RequestMapping("/user/userLevelCategory" )
public class UserLevelCategoryController {

    private final UserLevelCategoryService userLevelCategoryService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param userLevelCategory
     * @return 分页数据
     */
    @GetMapping("/page" )
    public ResponseEntity<IPage<UserLevelCategory>> getUserLevelCategoryPage(PageParam<UserLevelCategory> page, UserLevelCategory userLevelCategory) {
        return ResponseEntity.ok(userLevelCategoryService.page(page, new LambdaQueryWrapper<UserLevelCategory>()));
    }


    /**
     * 通过id查询
     * @param userLevelCategoryId id
     * @return 单个数据
     */
    @GetMapping("/info/{userLevelCategoryId}" )
    public ResponseEntity<UserLevelCategory> getById(@PathVariable("userLevelCategoryId") Long userLevelCategoryId) {
        return ResponseEntity.ok(userLevelCategoryService.getById(userLevelCategoryId));
    }

    /**
     * 新增
     * @param userLevelCategory
     * @return 是否新增成功
     */
    @SysLog("新增" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('user:userLevelCategory:save')" )
    public ResponseEntity<Boolean> save(@RequestBody @Valid UserLevelCategory userLevelCategory) {
        return ResponseEntity.ok(userLevelCategoryService.save(userLevelCategory));
    }

    /**
     * 修改
     * @param userLevelCategory
     * @return 是否修改成功
     */
    @SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('user:userLevelCategory:update')" )
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid UserLevelCategory userLevelCategory) {
        return ResponseEntity.ok(userLevelCategoryService.updateById(userLevelCategory));
    }

    /**
     * 通过id删除
     * @param userLevelCategoryId id
     * @return 是否删除成功
     */
    @SysLog("删除" )
    @DeleteMapping("/{userLevelCategoryId}" )
    @PreAuthorize("@pms.hasPermission('user:userLevelCategory:delete')" )
    public ResponseEntity<Boolean> removeById(@PathVariable Long userLevelCategoryId) {
        return ResponseEntity.ok(userLevelCategoryService.removeById(userLevelCategoryId));
    }

}
